<template>
  <Select
    v-model="formModel[widget.id]"
    v-bind="widget.elProps"
    :options="options"
    label-name="dictLabel"
    value-name="dictValue"
  ></Select>
</template>
<script setup lang="ts" name="SelectWidget">
import dictDataApi from "@/views/system/dict-data/api";
import { Select } from "@/components/Form";
import { ref, watch } from "vue";
const props = defineProps({
  widget: {
    type: Object
  },
  formModel: {
    type: Object
  }
});
const options = ref([]);
watch(
  () => props.widget!.elProps.dictType,
  async dictType => {
    if (dictType) {
      const res: Array<any> = await dictDataApi.list({ dictType });
      options.value = res;
    } else {
      options.value = [];
    }
  },
  {
    immediate: true
  }
);
</script>
<style lang="scss" scoped></style>
